/**
* Copyright (c) By zengqh.
*
* This program is just for fun or demo, in the hope that it  
* will be useful, you can redistribute it and/or modify freely.
*
* Time: 2013/05/20
* File: AreaOctree.h
* Blog: http://www.cnblogs.com/zengqh/
**/

#pragma once

#include "Octree.h"

namespace HY
{
class AreaOctree
{
public:
	AreaOctree();
	~AreaOctree();

public:
	void setAreaRoot( SceneNode* root ) { area_root_ = root; }
	void initOctree( const BoundingBox& box, int maxDepth );

	/** update. */
	void updateMaxDepth( int maxDepth );
	void updateAreaBox( const BoundingBox& box );
	void updateSceneNodeInOctree( SceneNode* node );

	/** get. */
	const BoundingBox& getCullBoundBox() const;

public:

	enum Visibility
	{
		NONE,
		PARTIAL,
		FULL
	};

	enum ActionResult
	{
		CONTINUE,
		END
	};

	struct IFindObjectCallback
	{
		virtual Visibility   onTestAABB( const BoundingBox& box ) = 0;
		virtual ActionResult onTestObject( Octree::ObjectType* obj, Visibility vis ) = 0;
	};

	ActionResult findObject( IFindObjectCallback* fn );

protected:
	ActionResult _findObject( OctreeNode* octNode, IFindObjectCallback* fn, Visibility parentVis );

protected:
	SceneNode*		area_root_;
	Octree*			octree_;
};
}